# 区分 东南西北 方位词 子方法
def capitalize_pinyin(cell_list):
    process_direction(cell_list, "qián")  # 前
    # process_direction(cell_list, "jiē")  # 街
    # process_direction(cell_list, "wài")  # 外
    # process_direction(cell_list, "dǐng")  # 顶
    # process_direction(cell_list, "xià")  # 下
    # process_direction(cell_list, "zuǒ")  # 左
    # process_direction(cell_list, "yòu")  # 右
    # process_direction(cell_list, "cūn")  # 右

    process_direction(cell_list, "xīnzhài")  # 新寨
    process_direction(cell_list, "cítáng")  # 新寨
    process_direction(cell_list, "zōngcí")  # 新寨
    process_direction(cell_list, "gōngyuán")  # 新寨
    process_direction(cell_list, "hòutīng")  # 后厅
    process_direction(cell_list, "hòutīng")  # 后厅
    process_direction(cell_list, "zhōngxuéhòu")  # 中学后
    process_direction(cell_list, "sānbìliánwéi")  # 三壁联围
    process_direction(cell_list, "lǎozhài")  # 老寨
    process_direction(cell_list, "xīncuò")  # 新厝
    process_direction(cell_list, "lǎocuò")  # 老厝
    process_direction(cell_list, "hòulóu")  # 后楼
    process_direction(cell_list, "xīncūn")  # 新村
    process_direction(cell_list, "fǎnzhào")  # 反照

    process_direction(cell_list, "dōngpáng")  # 东旁
    process_direction(cell_list, "nánpáng")  # 南旁
    process_direction(cell_list, "xīpáng")  # 西旁
    process_direction(cell_list, "běipáng")  # 北旁
    process_direction(cell_list, "dōngwéi")  # 东围
    process_direction(cell_list, "nánwéi")  # 南围
    process_direction(cell_list, "xīwéi")  # 西围
    process_direction(cell_list, "běiwéi")  # 北围
    process_direction(cell_list, "xīqū")  # 西区
    process_direction(cell_list, "dōngqū")  # 东区

    process_direction(cell_list, "tīngnèi")  # 正厅


    process_direction(cell_list, "zhèngzuò")  # 正厅
    process_direction(cell_list, "xītīng")  # 西厅
    process_direction(cell_list, "dōngtīng")  # 东厅
    process_direction(cell_list, "nántīng")  # 南厅
    process_direction(cell_list, "běitīng")  # 北厅
    process_direction(cell_list, "xīnzuò")  # 新座
    process_direction(cell_list, "xīzuò")  # 西座
    process_direction(cell_list, "běizuò")  # 北座
    process_direction(cell_list, "nánzuò")  # 南座
    process_direction(cell_list, "dōngzuò")  # 东座
    process_direction(cell_list, "zhōngzuò")  # 中座
    process_direction(cell_list, "hòuzuò")  # 后座
    process_direction(cell_list, "qiánzuò")  # 前座
    process_direction(cell_list, "zhíxiàng")  # 直巷

    process_direction(cell_list, "bógōnggōng")  # 伯公宫
    process_direction(cell_list, "sānbìlián")  # 三壁联
    # process_direction(cell_list, "chíwěi")  # 池尾
    process_direction(cell_list, "cuòdì")  # 厝地

    process_direction(cell_list, "liánchí")  # 莲池
    process_direction(cell_list, "cítáng")  # 祠堂
    process_direction(cell_list, "lǎocuòwéi")  # 老厝围
    process_direction(cell_list, "huīchéngtóu")  # 灰埕头
    process_direction(cell_list, "xīncuòwéi")  # 新厝围
    process_direction(cell_list, "lǐngqiánwéi")  # 岭前围
    process_direction(cell_list, "lǐnghòuwéi")  # 岭后围
    process_direction(cell_list, "zhàinèiwéi")  # 寨内围
    process_direction(cell_list, "dǐngzuò")  # 顶座
    process_direction(cell_list, "zhàiqiánwéi")  # 寨前围
    process_direction(cell_list, "jiānshídàzhài")  # 寨前围
    process_direction(cell_list, "kēngwéi")  # 寨前围



    process_direction(cell_list, "xī")  # 西
    process_direction(cell_list, "dōng")  # 东
    process_direction(cell_list, "héng")  # 横
    process_direction(cell_list, "zhí")  # 直
    process_direction(cell_list, "nán")  # 南
    process_direction(cell_list, "běi")  # 北
    process_direction(cell_list, "hòu")  # 后
    process_direction(cell_list, "nèi")  # 内
    process_direction(cell_list, "zhōng")  # 中
    process_direction(cell_list, "zhèng")  # 正
    process_direction(cell_list, "lùxià")  # 路下
    process_direction(cell_list, "lùdǐng")  # 路顶
    process_direction(cell_list, "lù")  # 路



    process_number_direction(cell_list, "yīwéi", "1", "wéi")
    process_number_direction(cell_list, "èrwéi", "2", "wéi")
    process_number_direction(cell_list, "sānwéi", "3", "wéi")
    process_number_direction(cell_list, "sìwéi", "4", "zuo")
    process_number_direction(cell_list, "wǔwéi", "5", "zuo")
    process_number_direction(cell_list, "liùwéi", "6", "zuo")
    process_number_direction(cell_list, "wǔjiānguò", "5", "jiānguò")
    process_number_direction(cell_list, "liùjiānguò", "6", "jiānguò")

    process_number_direction(cell_list, "yīzuò", "1", "zuo")
    process_number_direction(cell_list, "èrzuò", "2", "zuo")
    process_number_direction(cell_list, "sānzuò", "3", "zuo")
    process_number_direction(cell_list, "sìzuò", "4", "zuo")
    process_number_direction(cell_list, "wǔzuò", "5", "zuo")
    process_number_direction(cell_list, "liùzuò", "6", "zuo")
    process_number_direction(cell_list, "qīzuò", "7", "zuo")
    process_number_direction(cell_list, "bāzuò", "8", "zuo")
    process_number_direction(cell_list, "bāzuò", "8", "zuo")
    process_number_direction(cell_list, "yītīng", "1", "tīng")
    process_number_direction(cell_list, "èrtīng", "2", "tīng")
    process_number_direction(cell_list, "sāntīng", "3", "tīng")
    process_number_direction(cell_list, "sìtīng", "4", "tīng")
    process_number_direction(cell_list, "wǔtīng", "5", "tīng")
    process_number_direction(cell_list, "liùtīng", "6", "tīng")

    # process_end_direction(cell_list, "xiàng")
    return cell_list[0]


def process_number_direction(cell_list, direction, number, px):
    lang = len(direction)
    lastStr = cell_list[0][-len(direction):]
    topStr = cell_list[0][:-len(direction)]
    zuo = cell_list[0][-len(px):].capitalize()
    if lastStr == direction:
        lastStr = number + " " + zuo
        cell_list[0] = topStr + " " + lastStr


def process_direction(cell_list, direction):
    lang = len(direction)
    lastStr = cell_list[0][-len(direction):]
    topStr = cell_list[0][:-len(direction)]
    if lastStr == direction:
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized


def process_end_direction(cell_list, direction):
    lang = len(cell_list)
    lastStr = cell_list[lang - 1][-len(direction):]
    topStr = cell_list[lang - 1][:-len(direction)]
    if lastStr == direction:
        result_capitalized = lastStr.capitalize()
        cell_list[lang - 1] = topStr + " " + result_capitalized


# 单个字符串分割路、巷 例如：五行东路
def capitalize_lu_pinyin(cell_list):
    endStr = ""

    lastStr = cell_list[0][-8:]
    topStr = cell_list[0][:-8]
    if lastStr == "yòuxiàng":  # 右巷
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized
        return cell_list[0]

    lastStr = cell_list[0][-8:]
    topStr = cell_list[0][:-8]
    if lastStr == "zuǒxiàng":  # 左巷
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized
        return cell_list[0]

    lastStr = cell_list[0][-8:]
    topStr = cell_list[0][:-8]
    if lastStr == "běilù":  # 北路
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized
        return cell_list[0]

    lastStr = cell_list[0][-8:]
    topStr = cell_list[0][:-8]
    if lastStr == "nánlù":  # 南路
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized
        return cell_list[0]

    lastStr = cell_list[0][-9:]
    topStr = cell_list[0][:-9]
    if lastStr == "dōnglù":  # 东路
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized
        return cell_list[0]

    lastStr = cell_list[0][-7:]
    topStr = cell_list[0][:-7]
    if lastStr == "xīlù":  # 西路
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized
        return cell_list[0]

    lastStr = cell_list[0][-8:]
    topStr = cell_list[0][:-8]
    if lastStr == "běixiàng":  # 北巷
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized
        return cell_list[0]

    lastStr = cell_list[0][-8:]
    topStr = cell_list[0][:-8]
    if lastStr == "nánxiàng":  # 南巷
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized
        return cell_list[0]

    lastStr = cell_list[0][-9:]
    topStr = cell_list[0][:-9]
    if lastStr == "dōngxiàng":  # 东巷
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized
        return cell_list[0]

    lastStr = cell_list[0][-7:]
    topStr = cell_list[0][:-7]
    if lastStr == "xīxiàng":  # 西巷
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized
        return cell_list[0]

    lastStr = cell_list[0][-9:]
    topStr = cell_list[0][:-9]
    if lastStr == "héngxiàng":  # 横巷
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized
        return cell_list[0]

    lastStr = cell_list[0][-8:]
    topStr = cell_list[0][:-8]
    if lastStr == "zhíxiàng":  # 直巷
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized
        return cell_list[0]

    lastStr = cell_list[0][-8:]
    topStr = cell_list[0][:-8]
    if lastStr == "qiánxiàng":  # 前巷
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized
        return cell_list[0]

    lastStr = cell_list[0][-8:]
    topStr = cell_list[0][:-8]
    if lastStr == "zhōngxiàng":  # 中巷
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized
        return cell_list[0]

    lastStr = cell_list[0][-8:]
    topStr = cell_list[0][:-8]
    if lastStr == "hòuxiàng":  # 后巷
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized
        return cell_list[0]

    lastStr = cell_list[0][-5:]
    topStr = cell_list[0][:-5]
    if lastStr == "xiàng":  # 巷
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized
        return cell_list[0]

    lastStr = cell_list[0][-2:]
    topStr = cell_list[0][:-2]
    if lastStr == "lù":  # 路
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized
    return cell_list[0]

    lastStr = cell_list[0][-3:]
    topStr = cell_list[0][:-3]
    if lastStr == "jiē":  # 街
        result_capitalized = lastStr.capitalize()
        cell_list[0] = topStr + " " + result_capitalized
        return cell_list[0]

    # cell_list = cell_list[0].split()
    # endStr = capitalize_pinyin(cell_list)
    #
    # for value in cell_list[1:]:
    #     endStr += " " + str(value)
